package com.jiangyg.devtools.ui.table.cell;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;

import javax.swing.*;
import java.awt.*;

/**
 * 类描述：文本单元格编辑器
 *
 * @author jiangyg
 * @date 2023-08-29
 */
public class JavaBaseTypeComboBoxCellEditor extends AbstractTableCellEditor {

    private final ComboBox<String> combo = new ComboBox<>();

    public JavaBaseTypeComboBoxCellEditor(Project project) {
        super(project);

        initComboData();
    }

    private void initComboData() {
        combo.addItem(byte.class.getName());
        combo.addItem(char.class.getName());
        combo.addItem(boolean.class.getName());
        combo.addItem(int.class.getName());
        combo.addItem(long.class.getName());
        combo.addItem(double.class.getName());
        combo.addItem(float.class.getName());
        combo.addItem(java.lang.Character.class.getName());
        combo.addItem(java.lang.Boolean.class.getName());
        combo.addItem(java.lang.Short.class.getName());
        combo.addItem(java.lang.Integer.class.getName());
        combo.addItem(java.lang.Long.class.getName());
        combo.addItem(java.lang.Double.class.getName());
        combo.addItem(java.lang.Float.class.getName());
        combo.addItem(java.lang.String.class.getName());
        combo.addItem(java.util.Date.class.getName());
        combo.addItem(java.sql.Date.class.getName());
        combo.addItem(java.sql.Clob.class.getName());
        combo.addItem(java.sql.Blob.class.getName());
    }

    @Override
    public Component getTableCellEditorComponent(JTable table,
                                                 Object value,
                                                 boolean isSelected,
                                                 int row, int column) {
        combo.setSelectedItem(value);
        return combo;
    }

    @Override
    public Object getCellEditorValue() {
        return combo.getItem();
    }

}
